<ui:composition template="/template/twocolumn-academico.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">


       <ui:define name="item-menu-top">
    </ui:define>
    
    <ui:define name="conteudo">
        <h3>Conteúdo</h3>
    <h:form id="form" enctype="multipart/form-data">
        <p:messages id="messages" showDetail="false" globalOnly="true" autoUpdate="true" closable="true" /> 
        <h:panelGrid id="pgcadastro" columns="3">
                
                <p:outputLabel id="lTipo" value="#{Message['label.conteudo.tipo']}:" />
                <h:selectOneMenu requiredMessage="Informe o tipo do conteúdo" required="true" style="width:270px" id="tipo" 
                value="#{conteudoAcademicoMB.tipo}">
                <f:selectItem itemLabel="-- Selecione --" noSelectionOption="true"/>
                <f:selectItems value="#{conteudoAcademicoMB.tiposItens}" var="tipo"
                itemLabel="#{tipo.descricao}" itemValue="#{tipo.chave}" />
                </h:selectOneMenu>
                <h:message for="tipo" errorStyle="color:red"/>
                
                <h:outputLabel id="lNome" value="#{Message['label.global.nome']}:" />
                <h:inputText id="nome" required="true" requiredMessage="Informe o nome do arquivo"
                 value="#{conteudoAcademicoMB.conteudoAcademico.nome}" />
                <h:message for="nome" errorStyle="color:red"/>
                
                <h:outputLabel id="ldescricao" value="#{Message['label.conteudo.descricao']}:" />
                <h:inputText id="descricao" required="true" requiredMessage="Informe um descrição para o conteúdo" 
                value="#{conteudoAcademicoMB.conteudoAcademico.descricao}" />
                <h:message for="descricao" errorStyle="color:red"/>
                
                <h:outputLabel id="lArquivo" value="#{Message['label.conteudo.arquivo']}:" />
                <p:fileUpload required="true" id="arquivo" value="#{conteudoAcademicoMB.file}" mode="simple"
                sizeLimit="10000" invalidSizeMessage="Arquivo maior que o permitido"
                 allowTypes="/(\.|\/)(pdf|doc|docx|ppt|pptx|xls|xlsx|txt)$/"/>  
                <h:message for="arquivo" errorStyle="color:red"/>
                
                 <h:outputLabel id="lNotificar" value="Notificação:" />
                <p:selectBooleanButton value="#{conteudoAcademicoMB.enviarNotificacao}"  onLabel="Sim" offLabel="Não" onIcon="ui-icon-check" offIcon="ui-icon-close" />  
        </h:panelGrid>
                
                <p:toolbar>  
                    <p:toolbarGroup align="left">  
              		<p:commandButton value="Adicionar" update=":form:dtConteudos"  action="#{conteudoAcademicoMB.adicionarConteudo}" validateClient="true" ajax="false" />
					<p:commandButton value="Cancelar" action="#{conteudoAcademicoMB.cancelar}" immediate="true" ajax="false" icon="ui-icon-cancel"  />
					<p:commandButton value="Limpar" type="reset" ajax="false" icon="ui-icon-clear"  />
					</p:toolbarGroup>
				</p:toolbar>
        
        <div class="separador"></div>
         </h:form>    
         <h:form id="form2">
        <p:dataTable id="dtConteudos" value="#{conteudoAcademicoMB.conteudoAcademicos}" var="conteudo" editable="true"
        emptyMessage="nenhum registro encontrado"
         paginator="#{conteudoAcademicoMB.conteudoAcademicos.size() > 5}" rows="10" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks}
           {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5,10,15" style="width: 100%" lazy="true">
                
                <p:ajax event="rowEdit" listener="#{conteudoAcademicoMB.alterarConteudo(conteudo)}" update=":form:messages" />  
                <p:ajax event="rowEditCancel" listener="#{conteudoAcademicoMB.cancelarAlteracao}" update=":form:messages" />  
                   
                <p:column headerText="Nome">
                    <p:cellEditor>
                        <f:facet name="output">
                        <h:outputText value="#{conteudo.nome}" />
                        </f:facet>
                        <f:facet name="input">
                        <h:inputText value="#{conteudo.nome}" size="15" />
                        </f:facet>
                    </p:cellEditor>
                </p:column>
                
                 <p:column headerText="Tipo">
                    <p:cellEditor>
                        <f:facet name="output">
                        <h:outputText value="#{conteudo.tipoConteudo.descricao}" />
                        </f:facet>
                         <f:facet name="input">
                         <h:selectOneMenu style="width:100px" id="tipo" value="#{conteudoAcademicoMB.tipo}"
                         >
                		<f:selectItem itemLabel="-- Selecione --" noSelectionOption="true"/>
                		<f:selectItems value="#{conteudoAcademicoMB.tiposItens}" var="tipo"
               			 itemLabel="#{tipo.descricao}" itemValue="#{tipo.chave}" />
                		</h:selectOneMenu>
                        </f:facet>
                        </p:cellEditor>
                    </p:column>
                    
                  <p:column headerText="Data Postagem">
                    <p:cellEditor>
                        <f:facet name="output">
                        <h:outputText value="#{conteudo.dataPostagem}" />
                        </f:facet>
                         <f:facet name="input">
                        <p:calendar value="#{conteudo.dataPostagem}" readonly="true" size="15"/>
                        </f:facet>
                        </p:cellEditor>
                    </p:column>
                    
                   <p:column headerText="Descrição">
                    <p:cellEditor>
                        <f:facet name="output">
                        <h:outputText value="#{conteudo.descricao}" />
                        </f:facet>
                        <f:facet name="input">
                        <h:inputTextarea value="#{conteudo.descricao}" style="width: 100px;"/>
                        </f:facet>
                        </p:cellEditor>
                    </p:column>
                    
                   <p:column headerText="Arquivo">
                    <p:cellEditor>
                        <f:facet name="output">
                        <h:outputText value="#{conteudo.arquivo}" />
                        </f:facet>
                          <f:facet name="input">
                        <p:fileUpload id="arquivo" value="#{conteudoAcademicoMB.file}" mode="simple" update="alert" 
                		 style="width: 120px;"	sizeLimit="10000000" allowTypes="/(\.|\/)(pdf|doc|docx|ppt|pptx|xls|xlsx|txt)$/"/>  
                        </f:facet>
                        </p:cellEditor>
                    </p:column>
                    
                  <p:column style="width:5%">  
                    <p:rowEditor />  
                </p:column>  
                  <p:column>
                   <p:commandButton value="Excluir" update="dtConteudos" ajax="true" 
                	action="#{conteudoAcademicoMB.excluirConteudo(conteudo)}" />
                </p:column>
            </p:dataTable>
            
   </h:form>        
    </ui:define>

</ui:composition>